package com.lx.rabbitmq.three;

import com.lx.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

/**
 * 生产者 持久化队列
 * @author lixing
 * @date 2021/9/28 14:43
 */
public class Task2 {
    private static final String TASK_QUEUE_NAME = "ack_queue";

    public static void main(String[] argv) throws Exception {
        try (Channel channel = RabbitMqUtils.getChannel()) {

            //声明队列
            boolean durable = true;//需要让Queue持久化
            channel.queueDeclare(TASK_QUEUE_NAME, durable, false, false,null);
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入信息");
            while (sc.hasNext()) {
                String message = sc.nextLine();
                //设置生产者发送消息为持久化消息(要求保存到磁盘上)
                channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes("UTF-8"));
                System.out.println("生产者发出消息" + message);
            }
        }

    }
}